import { UserProfilesAPI } from '@/request/api'
export default {
    namespaced: true,
    state: {
        //用户信息
        userInfo: {
            //昵称
            nickName: "昵称",
            //鸡腿数
            coin: "--",
            //头像
            headImg: require("../../assets/img/service.848ec511.png")
        },
        //购物车总数
        cartTotal: 88
    },
    getters: {
    },
    mutations: {
        //修改用户信息
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo;
            state.cartTotal = payload.cartTotal;
        },
        //初始化用户信息
        initUserInfo(state) {
            state.userInfo = {
                //昵称
                nickName: "昵称",
                //鸡腿数
                coin: "--",
                //头像
                headImg: require("../../assets/img/service.848ec511.png")
            }
        }

    },
    actions: {
        async asyncChangeUserInfo({ commit }) {
            //发送请求  异步
            let user = await UserProfilesAPI()
            // console.log("asyncChangeUserInfo：", user);
            //调用mutation方法，更新state的数据
            commit("changeUserInfo", user.data)
        }
    },
}